package com.probiz.estore.exception;

import com.probiz.estore.common.model.product.ProductSku;
import com.probiz.estore.core.util.I18nUtil;

/**
 * 低于商品的最低购买数量异常
 * @since V3.0
 */
public class UnderMinimumPurchaseQuantityException extends Exception {
	
	private static final long	serialVersionUID	= 7445963130649662622L;
	
	private ProductSku productSku;
	private Integer purchaseQuantity;

	public UnderMinimumPurchaseQuantityException(ProductSku productSku, Integer purchaseQuantity) {
		super();
		this.productSku = productSku;
		this.purchaseQuantity = purchaseQuantity;
	}
	
	public UnderMinimumPurchaseQuantityException() {
		super();
	}

	@Override
	public String getMessage() {
		if (productSku != null) {
			if (productSku.getProduct().getMinOrderQuantity() == null) {
				return I18nUtil.getInstance().getMessage("shoppingcart.detail.underMinimumPurchaseQuantity1", 
						new Object[] {productSku.getProductSkuName(), 1});
			} else {
				return I18nUtil.getInstance().getMessage("shoppingcart.detail.underMinimumPurchaseQuantity1", 
						new Object[] {productSku.getProductSkuName(), productSku.getProduct().getMinOrderQuantity()});
			}
		} else {
			return I18nUtil.getInstance().getMessage("shoppingcart.detail.underMinimumPurchaseQuantity2");
		}
	}

}
